//
// Created by Javery Chiang on 2025/5/4.
//

#ifndef CMAKECXX_GRAPH_H
#define CMAKECXX_GRAPH_H

#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <unordered_set>

using namespace std;

class Graph {
private:
    int V;
    vector<vector<int>> adj;
public:
    Graph(int vertices) : V(vertices), adj(vertices) {}

    void addEdge(int u, int v) {
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    void DFS(int start);

    void DFS_Iterative(int start);

    void BFS(int start);

private:
    void DFSUtil(int v, unordered_set<int> &visited) {
        visited.insert(v);
        cout << v << " ";
        for (int neighbor: adj[v]) {
            if (visited.find(neighbor) == visited.end()) {
                DFSUtil(neighbor, visited);
            }
        }

    }

};


#endif //CMAKECXX_GRAPH_H
